<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
    <th:block th:include="common/include :: header('订单列表')"/>
</head>
<body class="gray-bg">
<div class="container-div">
    <div class="row">
        <div class="col-sm-12 search-collapse">
            <form id="customer-form">
                <div class="select-list">
                    <ul>
                        <li>
                            订单编号：<input type="text" name="orderSn"/>
                        </li>
                        <li>
                            预留电话：<input type="text" name="mobile"/>
                        </li>
                        <li>
                            订单分类：
                            <select name="type" th:with="items=${@dict.getType('business_order_type')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            订单状态：
                            <select name="orderState" th:with="items=${@dict.getType('business_order_state')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            支付状态：
                            <select name="payState" th:with="items=${@dict.getType('business_order_pay_state')}">
                                <option value="">所有</option>
                                <option th:each="item : ${items}" th:text="${item.label}"
                                        th:value="${item.value}"></option>
                            </select>
                        </li>
                        <li>
                            <a class="btn btn-primary btn-rounded btn-sm" onclick="$.table.search()"><i
                                    class="fa fa-search"></i>&nbsp;搜索</a>
                            <a class="btn btn-warning btn-rounded btn-sm" onclick="$.form.reset()"><i
                                    class="fa fa-refresh"></i>&nbsp;重置</a>
                        </li>
                    </ul>
                </div>
            </form>
        </div>

        <div class="col-sm-12 select-table table-striped">
            <table id="bootstrap-table"></table>
        </div>
    </div>
</div>
<th:block th:include="common/include :: footer"/>
<script th:inline="javascript">
    var orderStateData = [[${@dict.getType('business_order_state')}]];
    var orderPayStateData = [[${@dict.getType('business_order_pay_state')}]];
    var orderTypeData = [[${@dict.getType('business_order_type')}]];


    var detailFlag = [[${@permission.hasPermi('business:orders:detail')}]];
    var removeFlag = [[${@permission.hasPermi('business:orders:remove')}]];
    var confirmFlag = [[${@permission.hasPermi('business:orders:confirm')}]];
    var refundFlag = [[${@permission.hasPermi('business:orders:refund')}]];
    var prefix = ctx + "/business/orders";
    $(function () {
        var options = {
            url: prefix + "/query",
            createUrl: prefix + "/addPage",
            updateUrl: prefix + "/editPage?id={id}",
            removeUrl: prefix + "/remove",
            uniqueId: 'id',
            modalName: "订单",
            columns: [{
                checkbox: true
            },
                {
                    field: 'id',
                    title: '编号',
                    visible: false
                },
                {
                    field: 'orderSn',
                    title: '订单编号'
                },
                {
                    field: 'username',
                    title: '用户名',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 4, "open");
                    }
                },
                {
                    field: 'consigneeName',
                    title: '收货人'
                },
                {
                    field: 'mobile',
                    title: '预留电话'
                },
                {
                    field: 'fullAddress',
                    title: '收货地址',
                    formatter: function(value, row, index) {
                        return $.table.tooltip(value, 4, "open");
                    }
                },
                {
                    field: 'goodsPrice',
                    title: '商品总价'
                },
                {
                    field: 'orderPrice',
                    title: '订单总价'
                },
                {
                    field: 'type',
                    title: '订单类型',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderTypeData, value);
                    }
                },
                {
                    field: 'orderState',
                    title: '订单状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderStateData, value);
                    }
                },
                {
                    field: 'payState',
                    title: '支付状态',
                    formatter: function (value, row, index) {
                        return $.table.selectDictLabel(orderPayStateData, value);
                    }
                },
                {
                    field: 'takesTime',
                    title: '自取时间'
                },
                {
                    field: 'orderTime',
                    title: '下单时间'
                },
                {
                    field: 'remark',
                    title: '备注'
                },
                {
                    title: '操作',
                    align: 'center',
                    formatter: function (value, row, index) {
                        var confirmFlagTemp = confirmFlag;
                        var refundFlagTemp = refundFlag;

                        // 配送
                        if (row.type === 0) {
                            if (!(row.payState === 1 && row.orderState === 1)) {
                                confirmFlagTemp += 'disabled';
                            }
                        } else if (row.type === 1) {    // 自取
                            if (!(row.payState === 1 && row.orderState === 2)) {
                                confirmFlagTemp += 'disabled';
                            }
                        }
                        if (row.payState !== 4) {
                            refundFlagTemp += 'disabled';
                        }
                        var actions = [];
                        actions.push('<a class="btn btn-info btn-xs ' + detailFlag + '" href="javascript:void(0)" onclick="detail(\'' + row.id + '\')"><i class="fa fa-search"></i>明细</a> ');
                        actions.push('<a class="btn btn-primary btn-xs ' + confirmFlagTemp + '" href="javascript:void(0)" onclick="confirm(\'' + row.id + '\')"><i class="fa fa-truck"></i>已配送/已自取</a> ');
                        actions.push('<a class="btn btn-success btn-xs ' + refundFlagTemp + '" href="javascript:void(0)" onclick="refund(\'' + row.id + '\')"><i class="fa fa-reply"></i>退款</a> ');
                        var more = [];
                        more.push("<a class='btn btn-default btn-xs " + removeFlag + "' href='javascript:void(0)' onclick='$.operate.remove(" + row.id + ")'><i class='fa fa-remove'></i>删除</a>");
                        actions.push('<a tabindex="0" class="btn btn-info btn-xs" role="button" data-container="body" data-placement="left" data-toggle="popover" data-html="true" data-trigger="hover" data-content="' + more.join('') + '"><i class="fa fa-chevron-circle-right"></i>更多操作</a>');
                        return actions.join('');
                    }
                }
            ]
        };
        $.table.init(options);
    });
    function detail(id) {
        var url = ctx + '/business/orders/detail?orderId=' + id;
        $.modal.openTab("订单明细", url);
    }
    function confirm(id) {
        $.modal.confirm("确定已配送/已自取吗？", function() {
            var url = ctx + '/business/orders/confirm?orderId=' + id;
            $.operate.get(url);
        });
    }
    function refund(id) {
        $.modal.confirm("确定已配送/已自取吗？", function() {
            var url = ctx + '/business/orders/refund?orderId=' + id;
            $.operate.get(url);
        });
    }
</script>
</body>
</html>